<?php

namespace app\admin\controller;

use app\admin\BaseController;
use app\admin\model\HonorModel;


class Honor extends BaseController
{
    public function query()
    {
        $params = $this->request->param();

        $list = HonorModel::paginate([
            'list_rows' => $params['pageSize'],
            'page' => $params['pageNo']
        ]);

        return show($list);



    }

    public function add()
    {
        $params = $this->request->param();

        if(empty($params['content'])) {
            return show([],400,'缺少关键参数content');
        }

        HonorModel::create([
            'content' => $params['content'],
            'village_id' => $this->villageId
        ]);

        return show();



    }

    public function edit()
    {

        $params = $this->request->param();

        if(empty($params['content'])) {
            return show([],400,'缺少关键参数content');
        }

        if(empty($params['id'])) {
            return show([],400,'缺少关键参数id');
        }

        $honorModel = HonorModel::find($params['id']);
        $honorModel->content = $params['content'];
        $honorModel->save();

        return show();

    }

    public function del()
    {
        $params = $this->request->param();

        HonorModel::destroy($params['id']);

        return show();

    }
}